<template>
    <div class="container">
        <div class="header">
            <van-nav-bar left-arrow @click-left="onClickLeft" @click-right="onClickRight">
                <template #right>
                    <van-icon name="search" size="27" />
                </template>
            </van-nav-bar>
        </div>

        <van-search v-model="keyWord" shape="round" background="#F0F0F0" :placeholder="keyWord" />
        <div class="filter">
            <span>全城
                <van-icon name="arrow-down" /></span>
            <span>全部分类
                <van-icon name="arrow-down" /></span>
            <span>智能排序
                <van-icon name="arrow-down" /></span>
        </div>

        <div class="main">
            <div class="item" v-for="item in List" :key="item.id">
                <div class="img">
                    <div class="item-pic">12.12</div>
                    <img :src="item.img">
                </div>
                <div class="content">
                    <span>{{item.name}}</span>
                    <div class="pingjia">
                        <span class="l"><span class="shopRate"></span></span>
                        <span>{{item.pingfen}}</span>
                        <span>{{item.pingluns}}条</span>
                        <span>￥{{item.price}}/人</span>
                    </div>
                    <div class="keyword">
                        <span v-for="(keyword, index) in item.keyWords" :key="index">{{keyword}}</span>
                    </div>
                    <div class="condition">
                        <span v-for="(con, index) in item.condition" :key="index">{{con}}</span>
                    </div>
                    <div class="activity">
                        <div class="activityItem" v-for="active in item.activity" :key="active.id">
                            <span></span>
                            <span>[{{active.icon}}]</span>
                            <span>{{active.title}}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'SearchResult',
        data() {
            return {
                keyWord: '',
                categoryId: '',
                List: []
            }
        },
        created() {
            this.init(this.$route.params.categoryId, this.$route.query.keyWord);
            this.keyWord = this.$route.query.keyWord;
            this.categoryId = this.$route.params.categoryId;
        },
        methods: {
            onClickLeft() {
                this.$router.push('/home')
            },
            onClickRight() {
                this.$router.push('/search')
            },
            async init(categoryId, keyWord) {
                if (categoryId) {
                    const result = await this.$API.searchList(categoryId);
                    if (result.code == 200) {
                        this.List = result.list.list
                    }
                } else {
                    const result = await this.$API.searchKeyWord(keyWord);
                    this.List = result.list;
                }
            }
        }
    }
</script>

<style lang='less' scoped>
    @import '../../assets/imgUrl.less';
    .container {
        .header {
            /deep/ .van-nav-bar {
                background-color: #F0F0F0;
            }

            /deep/ .van-nav-bar__arrow {
                font-size: 25px;
                color: #FF6633;
            }

            /deep/ .van-icon-search {
                color: #FF6633;
            }
        }

        .filter {
            display: flex;
            justify-content: space-between;
            padding: 0 10px;
            border-bottom: 1px solid #DDDDDD;

            span {
                font-size: 14px;
                text-align: center;
                padding: 13px 20px;
            }
        }

        .main {
            & .item {
                padding: 10px;
                overflow: hidden;

                .img {
                    float: left;
                    width: 66px;
                    height: 66px;
                    position: relative;

                    .item-pic {
                        width: 64px;
                        height: 16px;
                        color: white;
                        text-align: center;
                        font-size: 14px;
                        background-color: #FF6633;
                        position: absolute;
                        top: 3px;
                        left: -5px;
                    }

                    img {
                        width: 100%;
                        height: 100%;
                    }
                }

                .content {
                    margin-left: 10px;
                    float: left;

                    .pingjia {
                        margin: 5px 0 0;

                        .shopRate {
                            display: inline-block;
                            width: 66px;
                            height: 12px;
                            background-image: url("../../static/imgs/rate.png");
                            background-size: cover;
                            background-position: 0 -17px;
                        }

                        span {
                            &:nth-child(2) {
                                font-size: 15px;
                                color: #F34822;
                                margin: 0 10px 0 5px;
                            }

                            &:nth-child(3) {
                                font-size: 12px;
                                margin-right: 10px;
                            }

                            &:nth-child(4) {
                                font-size: 12px;
                            }
                        }
                    }

                    .keyword {
                        span {
                            color: #999999;
                            font-size: 12px;
                            margin-right: 10px;
                        }
                    }

                    .condition {
                        padding: 5px 0 12px;

                        span {
                            font-size: 12px;
                            background: #F8F6F6;
                            margin-right: 4px;
                            padding: 3px;
                        }
                    }

                    .activity {
                        .activityItem {
                            span {
                                vertical-align: middle;

                                &:first-child {
                                    width: 16px;
                                    height: 16px;
                                    display: inline-block;
                                    background-image: url("@{imgUrl}/imgs/3b9f373b9ab57cbc071502ef7941ad6d.png");
                                    background-position: -33px -49px;
                                    background-size: 115px auto
                                }

                                &:nth-child(2) {
                                    line-height: 12px;
                                    font-size: 14px;
                                    color: #FF6633;
                                }

                                &:last-child {
                                    display: inline-block;
                                    width: 200px;
                                    white-space: nowrap;
                                    overflow: hidden;
                                    text-overflow: ellipsis;
                                    line-height: 12px;
                                    font-size: 14px;
                                }
                            }
                        }
                    }
                }
            }

        }
    }
</style>